//
//  UserHomeTableViewCell.swift
//  甜言蜜语
//
//  Created by 王剑伟 on 16/6/14.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit
import SVProgressHUD
protocol UserHomeTableViewCellDelegate {
    func zanBtnClicked(id: String)
    func shareBtnClicked(id: String)
    func replyBtnClicked(id: String)
    
}
class UserHomeTableViewCell: UITableViewCell {
    
    var delegate:UserHomeTableViewCellDelegate!
    
    @IBOutlet weak var icon: UIImageView!
    @IBOutlet weak var name: UILabel!
    @IBOutlet weak var time: UILabel!
    @IBOutlet weak var context: UILabel!

    @IBOutlet weak var newImg: UIImageView!
    @IBOutlet weak var newsTitle: UILabel!
    
    @IBOutlet weak var zanBtn: UIButton!
    @IBOutlet weak var shareBtn: UIButton!
    @IBOutlet weak var replyBtn: UIButton!
    
    var model: CommentModel? {
        didSet {
            self.setupView()
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
//        self.zanBtn.hidden = true
//        self.shareBtn.hidden = true
//        self.replyBtn.hidden = true
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func setupView() {
        if self.model?.isdianzan == true{
          
            self.zanBtn.setBackgroundImage(UIImage (named: "zan_selected"), forState: UIControlState.Normal)
        }else{
            self.zanBtn.setBackgroundImage(UIImage (named: "zan"), forState: UIControlState.Normal)
        }
       
        icon.sd_setImageWithURL(NSURL(string: (model?.timg)!), placeholderImage:UIImage(named: "placeholder"))
        name.text = model?.name
        time.text = model?.commentTime
        context.text = model?.message
        
        newImg.sd_setImageWithURL(NSURL(string: (model?.newsInfo.imgsrc)!))
        newsTitle.text = model?.newsInfo.title
    }
    
   @IBAction func shareClicked(){
    
    let dic = ["id": self.model!.newsInfo.NewsModelid]
    NSNotificationCenter.defaultCenter().postNotificationName(userShare_noti, object: dic)
    
    }
   @IBAction func zanClicked(){
    
   
    if self.model?.isdianzan == true{
        SVProgressHUD.showErrorWithStatus("您已经赞过")
        
    } else {
        DataTool.supposeComment(Int((self.model?.id)!)!, type:  "", completionHandler: { (isSuccess) -> Void in
            if isSuccess {
                self.zanBtn.setBackgroundImage(UIImage(named: "zan_selected"), forState: UIControlState.Normal)
            } else {
                
            }
        })

    }
    
    
    }
   @IBAction func replyClicked(){
    
    let dic = ["id": self.model!.newsInfo.NewsModelid]
    NSNotificationCenter.defaultCenter().postNotificationName(userReply_noti, object: dic)
    
    }
    
}
